<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP, MagicHash, UnboxedTuples #-}</span><span class="hs-cpp">

#if __GLASGOW_HASKELL__ &gt;= 701
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-7"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Module      :  Control.Concurrent.STM.TVar</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2004</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Portability :  non-portable (requires STM)</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- TVar: Transactional variables</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Control.Concurrent.STM.TVar</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-22"></span><span>        </span><span class="annot"><span class="hs-comment">-- * TVars</span></span><span>
</span><span id="line-23"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier">TVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier">newTVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier">newTVarIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier">readTVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#readTVarIO"><span class="hs-identifier">readTVarIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier">writeTVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar"><span class="hs-identifier">modifyTVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar%27"><span class="hs-identifier">modifyTVar'</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#stateTVar"><span class="hs-identifier">stateTVar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#swapTVar"><span class="hs-identifier">swapTVar</span></a></span><span class="hs-special">,</span><span class="hs-cpp">
#ifdef __GLASGOW_HASKELL__
</span><span>        </span><span class="annot"><a href="../../base/src/GHC.Conc.IO.html#registerDelay"><span class="hs-identifier">registerDelay</span></a></span><span class="hs-special">,</span><span class="hs-cpp">
#endif
</span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#mkWeakTVar"><span class="hs-identifier">mkWeakTVar</span></a></span><span>
</span><span id="line-37"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#ifdef __GLASGOW_HASKELL__
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.html#"><span class="hs-identifier">GHC.Conc</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Weak.html#"><span class="hs-identifier">GHC.Weak</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Sequential.STM</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- Like 'modifyIORef' but for 'TVar'.</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- | Mutate the contents of a 'TVar'. /N.B./, this version is</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- non-strict.</span><span>
</span><span id="line-50"></span><span class="hs-comment">--</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- @since 2.3</span><span>
</span><span id="line-52"></span><span id="local-6989586621679037482"><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar"><span class="hs-identifier hs-type">modifyTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037482"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679037482"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037482"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-53"></span><span id="modifyTVar"><span class="annot"><span class="annottext">modifyTVar :: forall a. TVar a -&gt; (a -&gt; a) -&gt; STM ()
</span><a href="Control.Concurrent.STM.TVar.html#modifyTVar"><span class="hs-identifier hs-var hs-var">modifyTVar</span></a></span></span><span> </span><span id="local-6989586621679037442"><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037442"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621679037441"><span class="annot"><span class="annottext">a -&gt; a
</span><a href="#local-6989586621679037441"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-54"></span><span>    </span><span id="local-6989586621679037440"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037440"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar a -&gt; STM a
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037442"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-55"></span><span>    </span><span class="annot"><span class="annottext">TVar a -&gt; a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037442"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; a
</span><a href="#local-6989586621679037441"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037440"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar"><span class="hs-pragma hs-type">modifyTVar</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-comment">-- | Strict version of 'modifyTVar'.</span><span>
</span><span id="line-60"></span><span class="hs-comment">--</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- @since 2.3</span><span>
</span><span id="line-62"></span><span id="local-6989586621679037439"><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar%27"><span class="hs-identifier hs-type">modifyTVar'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037439"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679037439"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037439"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-63"></span><span id="modifyTVar%27"><span class="annot"><span class="annottext">modifyTVar' :: forall a. TVar a -&gt; (a -&gt; a) -&gt; STM ()
</span><a href="Control.Concurrent.STM.TVar.html#modifyTVar%27"><span class="hs-identifier hs-var hs-var">modifyTVar'</span></a></span></span><span> </span><span id="local-6989586621679037437"><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037437"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621679037436"><span class="annot"><span class="annottext">a -&gt; a
</span><a href="#local-6989586621679037436"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-64"></span><span>    </span><span id="local-6989586621679037435"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037435"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar a -&gt; STM a
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037437"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-65"></span><span>    </span><span class="annot"><span class="annottext">TVar a -&gt; a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037437"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">(a -&gt; STM ()) -&gt; a -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a
</span><a href="#local-6989586621679037436"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037435"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-66"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#modifyTVar%27"><span class="hs-pragma hs-type">modifyTVar'</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | Like 'modifyTVar'' but the function is a simple state transition that can</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- return a side value which is passed on as the result of the 'STM'.</span><span>
</span><span id="line-71"></span><span class="hs-comment">--</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- @since 2.5.0</span><span>
</span><span id="line-73"></span><span id="local-6989586621679037471"><span id="local-6989586621679037472"><span class="annot"><a href="Control.Concurrent.STM.TVar.html#stateTVar"><span class="hs-identifier hs-type">stateTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037472"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679037472"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679037471"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679037472"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037471"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-74"></span><span id="stateTVar"><span class="annot"><span class="annottext">stateTVar :: forall s a. TVar s -&gt; (s -&gt; (a, s)) -&gt; STM a
</span><a href="Control.Concurrent.STM.TVar.html#stateTVar"><span class="hs-identifier hs-var hs-var">stateTVar</span></a></span></span><span> </span><span id="local-6989586621679037430"><span class="annot"><span class="annottext">TVar s
</span><a href="#local-6989586621679037430"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621679037429"><span class="annot"><span class="annottext">s -&gt; (a, s)
</span><a href="#local-6989586621679037429"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-75"></span><span>   </span><span id="local-6989586621679037428"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679037428"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar s -&gt; STM s
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar s
</span><a href="#local-6989586621679037430"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-76"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679037427"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037427"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679037426"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679037426"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">s -&gt; (a, s)
</span><a href="#local-6989586621679037429"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679037428"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-comment">-- since we destructure this, we are strict in f</span><span>
</span><span id="line-77"></span><span>   </span><span class="annot"><span class="annottext">TVar s -&gt; s -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar s
</span><a href="#local-6989586621679037430"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679037426"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-78"></span><span>   </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037427"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-79"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#stateTVar"><span class="hs-pragma hs-type">stateTVar</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span class="hs-comment">-- Like 'swapTMVar' but for 'TVar'.</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- | Swap the contents of a 'TVar' for a new value.</span><span>
</span><span id="line-84"></span><span class="hs-comment">--</span><span>
</span><span id="line-85"></span><span class="hs-comment">-- @since 2.3</span><span>
</span><span id="line-86"></span><span id="local-6989586621679037466"><span class="annot"><a href="Control.Concurrent.STM.TVar.html#swapTVar"><span class="hs-identifier hs-type">swapTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037466"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037466"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037466"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-87"></span><span id="swapTVar"><span class="annot"><span class="annottext">swapTVar :: forall a. TVar a -&gt; a -&gt; STM a
</span><a href="Control.Concurrent.STM.TVar.html#swapTVar"><span class="hs-identifier hs-var hs-var">swapTVar</span></a></span></span><span> </span><span id="local-6989586621679037422"><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037422"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621679037421"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037421"><span class="hs-identifier hs-var">new</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-88"></span><span>    </span><span id="local-6989586621679037420"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037420"><span class="hs-identifier hs-var">old</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar a -&gt; STM a
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037422"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-89"></span><span>    </span><span class="annot"><span class="annottext">TVar a -&gt; a -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037422"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037421"><span class="hs-identifier hs-var">new</span></a></span><span>
</span><span id="line-90"></span><span>    </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037420"><span class="hs-identifier hs-var">old</span></a></span><span>
</span><span id="line-91"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TVar.html#swapTVar"><span class="hs-pragma hs-type">swapTVar</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span class="hs-comment">-- | Make a 'Weak' pointer to a 'TVar', using the second argument as</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- a finalizer to run when 'TVar' is garbage-collected</span><span>
</span><span id="line-96"></span><span class="hs-comment">--</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- @since 2.4.3</span><span>
</span><span id="line-98"></span><span id="local-6989586621679037464"><span class="annot"><a href="Control.Concurrent.STM.TVar.html#mkWeakTVar"><span class="hs-identifier hs-type">mkWeakTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037464"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Weak.html#Weak"><span class="hs-identifier hs-type">Weak</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037464"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-99"></span><span id="mkWeakTVar"><span class="annot"><span class="annottext">mkWeakTVar :: forall a. TVar a -&gt; IO () -&gt; IO (Weak (TVar a))
</span><a href="Control.Concurrent.STM.TVar.html#mkWeakTVar"><span class="hs-identifier hs-var hs-var">mkWeakTVar</span></a></span></span><span> </span><span id="local-6989586621679037419"><span class="annot"><span class="annottext">t :: TVar a
</span><a href="#local-6989586621679037419"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679037417"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679037417"><span class="hs-identifier hs-var">t#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span id="local-6989586621679037416"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, () #)
</span><a href="#local-6989586621679037416"><span class="hs-identifier hs-var">finalizer</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Weak (TVar a) #))
-&gt; IO (Weak (TVar a))
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><span class="hs-identifier hs-var">IO</span></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Weak (TVar a) #))
 -&gt; IO (Weak (TVar a)))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Weak (TVar a) #))
-&gt; IO (Weak (TVar a))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679037415"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037415"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-100"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
-&gt; TVar a
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, Weak# (TVar a) #)
</span><span class="hs-identifier hs-var">mkWeak#</span></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679037417"><span class="hs-identifier hs-var">t#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar a
</span><a href="#local-6989586621679037419"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, () #)
</span><a href="#local-6989586621679037416"><span class="hs-identifier hs-var">finalizer</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037415"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679037414"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037414"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679037413"><span class="annot"><span class="annottext">Weak# (TVar a)
</span><a href="#local-6989586621679037413"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679037414"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Weak# (TVar a) -&gt; Weak (TVar a)
forall v. Weak# v -&gt; Weak v
</span><a href="../../base/src/GHC.Weak.html#Weak"><span class="hs-identifier hs-var">Weak</span></a></span><span> </span><span class="annot"><span class="annottext">Weak# (TVar a)
</span><a href="#local-6989586621679037413"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-101"></span></pre></body></html>